import { http } from "@/utils/http";
import type { Result, ResultTable, BooleanResult } from "@/utils/result";

/** 获取系统管理-用户管理列表 */
export const getUserPageList = (data?: object) => {
  return http.request<ResultTable>("post", "/sys-user/page-list", {
    data
  });
};

/** 系统管理-用户管理-获取所有角色列表 */
export const getAllRoleList = () => {
  return http.request<Result>("get", "/sys-role/all-role-list");
};

/** 系统管理-用户管理-根据userId，获取对应角色id列表（userId：用户id） */
export const getRoleIds = (userId?: string) => {
  return http.request<Result>("get", "/sys-use-role/list-role-ids/" + userId);
};

/** 获取系统管理-角色管理列表 */
export const getRoleList = (data?: object) => {
  return http.request<ResultTable>("post", "/sys-role/page-list", {
    data
  });
};

/** 获取系统管理-菜单管理列表 */
export const getMenuList = () => {
  return http.request<Result>("get", "/sys-menu/list");
};

/** 获取系统管理-部门管理列表 */
export const getDeptList = (data?: object) => {
  return http.request<Result>("get", "/sys-dept/list", {
    data
  });
};

/** 获取角色管理-权限-菜单权限 */
export const getRoleMenu = (data?: object) => {
  return http.request<Result>("get", "/sys-menu/list", {
    data
  });
};

/** 获取角色管理-权限-菜单权限-根据角色 id 查对应菜单 */
export const getRoleMenuIds = (id?: string) => {
  return http.request<Result>("get", "/sys-role-menu/role-menu-ids/" + id);
};
/** 创建部门 */
export const createDept = (data?: object) => {
  return http.request<BooleanResult>("post", "/sys-dept/create", {
    data
  });
};
/** 修改部门 */
export const modifyDept = (data?: object) => {
  return http.request<BooleanResult>("post", "/sys-dept/modify", {
    data
  });
};
/** 删除一个部门 */
export const deleteDept = (id?: string) => {
  return http.request<BooleanResult>("get", "/sys-dept/delete/" + id);
};
/** 创建角色 */
export const createRole = (data?: object) => {
  return http.request<BooleanResult>("post", "/sys-role/create", {
    data
  });
};
/** 修改角色 */
export const modifyRole = (data?: object) => {
  return http.request<BooleanResult>("post", "/sys-role/modify", {
    data
  });
};
/** 删除角色 */
export const deleteRole = (id: string) => {
  return http.request<BooleanResult>("get", "/sys-role/delete/" + id);
};
/** 停用或启用角色信息 */
export const updateRoleStatus = (data?: object) => {
  return http.request<BooleanResult>("post", "/sys-role/update-status", {
    data
  });
};
/** 删除菜单 */
export const deleteMenu = (id: string) => {
  return http.request<BooleanResult>("get", "/sys-menu/delete/" + id);
};
/** 创建菜单 */
export const createMenu = (data?: object) => {
  return http.request<BooleanResult>("post", "/sys-menu/create", {
    data
  });
};
/** 修改菜单 */
export const modifyMenu = (data?: object) => {
  return http.request<BooleanResult>("post", "/sys-menu/modify", {
    data
  });
};
/** 保存角色和菜单关系数据 */
export const saveRoleMenuIds = (data?: object) => {
  return http.request<BooleanResult>("post", "/sys-role-menu/authorized", {
    data
  });
};

/** 创建用户 */
export const createUser = (data?: object) => {
  return http.request<BooleanResult>("post", "/sys-user/create", {
    data
  });
};

/** 修改用户 */
export const modifyUser = (data?: object) => {
  return http.request<BooleanResult>("post", "/sys-user/modify", {
    data
  });
};

/** 用户分配角色 */
export const authorizedRole = (data?: object) => {
  return http.request<BooleanResult>("post", "/sys-use-role/authorized", {
    data
  });
};

/** 批量删除用户 */
export const batchDeleteUser = (ids?: string) => {
  return http.request<BooleanResult>(
    "get",
    "/sys-user/batchDeleteUser?userIds=" + ids
  );
};
/** 重置密码 */
export const restPassword = (data?: object) => {
  return http.request<BooleanResult>("post", "/sys-user/rest-password", {
    data
  });
};
